package com.domain;

import com.controller.ShootGame;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

/**
 * 英雄
 */
public class Hero extends Flying {

    /**单独自己的属性（用来描述类中对象的形容词）**/
    private int doubleFire;//声明双倍火力属性

    public int getDoubleFire() {
        return doubleFire;
    }

    public void setDoubleFire(int doubleFire) {
        this.doubleFire = doubleFire;
    }

    //方法（类中对象所具有的能力）
    public Hero() {
        setImage(ShootGame.hero0);//给图片属性赋值
        setWidth(getImage().getWidth());//给图片属性赋值
        setHeight(getImage().getHeight());//给图片的高赋值
        setLifr(10);//声明敌机的生命值
        this.doubleFire = 0;//火力
        setY(400);//给图片的y轴赋值
        setX(150);//给图片的x轴坐标赋值
        setImages(new BufferedImage[]{ShootGame.hero0, ShootGame.hero1});//使飞机移动喷气的图片
    }

    @Override
    public void move() {
        //使飞机移动喷气
        setIndex(getIndex()+1);
        setImage(getImages()[getIndex()%2]);
        //设置鼠标在图片里的坐标
        setX(getX()-getImage().getWidth()/2);
        setY(getY()-getImage().getHeight()/2);
    }

    /**画英雄机的方法**/
    public void paint(Graphics g) {
        g.drawImage(getImage(),getX(),getY(),null);//画英雄机
    }

    /**
     * 发射子弹
     * @return
     */
    public ArrayList<Bullet> launch(){
        //声明一个子弹集合
        ArrayList<Bullet> bullets = new ArrayList<Bullet>();
        //默认火力
        if (doubleFire <= 0){
            bullets.add(new Bullet(getX() + getImage().getWidth()/2 - ShootGame.bullet.getWidth()/2 , getY() - ShootGame.bullet.getHeight()));
        }else {
            //多倍火力
            for (int i = 0; i < doubleFire; i++) {
                bullets.add(new Bullet((getX() + getImage().getWidth()/2 - ShootGame.bullet.getWidth()/2) - (i%2==0?-(i*5+3):+(i*5+3)), getY() - ShootGame.bullet.getHeight()));
            }
        }
        return bullets;
    }

}
